/**
 * @param {number[]} plants
 * @param {number} capacity
 * @return {number}
 */
var wateringPlants = function (plants, capacity) {
    let res = 0, c = capacity
    for (let i = 0; i < plants.length; i++) {
        if (c >= plants[i]) c -= plants[i]
        else {
            res += i * 2
            c = capacity
        }
    }
    return res + plants.length - 1
};
/**
 * @param {number[]} plants
 * @param {number} capacity
 * @return {number}
 */
var wateringPlants = function (plants, capacity) {
    let res = 0, c = capacity
    for (let i = 0; i < plants.length; i++) {
        if (c >= plants[i]) c -= plants[i]
        else {

            res += i * 2
            c = capacity - plants[i]
        }

    }
    return res + plants.length
};